<script setup>
import { ref } from 'vue'
const userInfo = ref({
    id: 0,
    userId: '202215000349',
    userName: '',
    subject: '',
    idNumber:'',
    teacherName:'',
    room:''
})
const rules = {
    userName: [
        { required: true, message: '请输入用户昵称', trigger: 'blur' },
        {
            pattern: /^\S{2,10}$/,
            message: '昵称必须是2-10位的非空字符串',
            trigger: 'blur'
        }
    ],
    subject: [
        { required: true, message: '请输入专业', trigger: 'blur' },
    ],
    idNumber: [
        { required: true, message: '请输入身份证号', trigger: 'blur' },
    ],
    teacherName: [
        { required: true, message: '请输入班主任姓名', trigger: 'blur' },
    ],
    room: [
        { required: true, message: '请输入房间号', trigger: 'blur' },
    ],
}
import{userinfoChangeService,userinfoGetService}from '@/api/user.js'
const infoChange=async()=>{
let result=await userinfoChangeService(userInfo.value);
if(result.success===true){
    alert(result.data)
}
else{
    alert("修改失败")
}
}

const infoUpdate=async()=>{
    let result=await userinfoGetService()
    if(result.success===true){
        alert("更新成功")
    }else{
        alert("更新失败")
    }
}
</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>基本资料</span>
            </div>
        </template>
        <el-row>
            <el-col :span="12">
                <el-form :model="userInfo" :rules="rules" label-width="100px" size="large">
                    <el-form-item label="学号">
                        <el-input v-model="userInfo.userId" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="姓名" prop="userName">
                        <el-input v-model="userInfo.userName"></el-input>
                    </el-form-item>
                    <el-form-item label="专业" prop="subject">
                        <el-input v-model="userInfo.subject"></el-input>
                    </el-form-item>
                    <el-form-item label="身份证号" prop="idNumber">
                        <el-input v-model="userInfo.idNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="班主任" prop="teacherName">
                        <el-input v-model="userInfo.teacherName"></el-input>
                    </el-form-item>
                    <el-form-item label="宿舍" prop="room">
                        <el-input v-model="userInfo.room"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="infoUpdate">更新</el-button>
                        <el-button type="primary" @click="infoChange">提交修改</el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </el-card>
</template>